I try a rule for commerce along the lines of following pseudo pattern:

________________________________

Event: After updating an existing commerce product
Conditions: commerce-product:type == 'myProductType'
Actions:
- Load related entities(entity:[commerce-product], relation type:'myRelationType'), provide var: entity_list
- Loop: entity_list AS entity_list_item
________________________________

I would have assumed, that this allows me to target fields of the loaded entities (product display nodes), to inject (set) data sourced from my comerce-product. I can not get this done - there are no tokens for the fields that live on my display nodes.

I'd be most grateful if anyone can point me in the right direction, or just tell me in case it can not be done, so I can stop churning through the entire interweb.

Comments

acrazyanimal’s picture

I have been running into this issue since I started using the relation module. Stellar job on the relation module btw!

I've found several problems with the Loads related entities action. The first is that it returns a generic entity list so rules has no idea what fields might be available to it. The second is that the values in the list it does return are not the entity objects themselves, but the wrapped entity metadata structures. So even if you did specify the type of the returned entity list attempts to access the data would fail on execution. At least that is what I've found.

I've created a patch to fix both these problems. So an optional entity type parameter has been added. I've tested it on existing rules that use the Loads related entities action and it seems to upgrade just fine. I don't think changing the return format from the wrapper to the entity object will affect any existing rules since they weren't working before, but it may if anybody has written custom code to extract the info from the returned list. I would say this is a beware for people upgrading, but probably not all that common. By specifying an entity type to return it now allows you to access the functions directly in rules.

I'm attaching a second patch that includes both the above fixes and a new action Fetch relation endpoints to return related entities of a specific type found in a particular relation. This is needed as often I want to alter data on an existing relation or operate on its endpoints. The Loads related entities function doesn't allow you to be relation specific, nor would the endpoints [token] field. The coolest thing (IMHO) about this function is that it returns a single entity if you only select 1 in the How Many parameter or a list of entities of a specific type otherwise.

This also, address all the requests by @Itangalo in #1260262: More Rules actions! minus #4.

Status: Needs review » Needs work
acrazyanimal’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Assigned: Unassigned » acrazyanimal
Category: support » bug
Priority: Normal » Major
Status: Needs work » Needs review

This is in fact a bug, upping it to major only because I image many people are having this frustration and are hitting a wall if they are not a developer.

btw, the above patches are against the latest dev as of today.

acrazyanimal’s picture

acrazyanimal’s picture

7wonders’s picture

When using the "Loads related entities" after applying the 2nd patch, I get the following when going to pick the relation type:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /system/ajax
StatusText: error
ResponseText: Recoverable fatal error: Argument 2 passed to ctools_export_crud_load_multiple() must be an array, string given, called in /test.dev/sites/all/modules/relation/relation.module on line 453 and defined in ctools_export_crud_load_multiple() (line 102 of /test.dev/sites/all/modules/ctools/includes/export.inc).
acrazyanimal’s picture

@7wonders: which version did you apply the patch against. The patches I created were to be applied against dev back when I first posted them. Its likely they have diverged again and a new patch will be needed.

7wonders’s picture

Against the latest dev

chx’s picture

Re-uploading the patch, it seemed to apply for me.

chx’s picture

So, at least this passes tests (which means little cos the bot doesnt run the rules tests). acrazyanimal, 7wonders please report back whether it still works.

acrazyanimal’s picture

Status: Needs review » Needs work

@chx: I just applied the patch against the latest dev and received the same error reported by 7wonders when editing an existing rule already configured to use the "Loads related entities".

I will investigate further...

chx’s picture

THanks for the report! It's unlikely I can find the time to debug this any time soon so special thanks for investigating further.

acrazyanimal’s picture

Status: Needs work » Needs review
StatusFileSize
new13.93 KB

Got it. Missing array []. Not sure how that happened, it was done right on my initial copy. I must have messed it up before making the patch somehow??? weird.

Anyway, try testing this version out.

7wonders’s picture

yep, that did the job ;)

chx’s picture

chx’s picture

Oh crap I accidentally committed the previous one with the UI separation! Fixing.

chx’s picture

Status: Needs review » Fixed

Committed, thanks.

acrazyanimal’s picture

bollocks! chx you messed up my authorship cred ... its cool, accidents happen. Thanks for committing. ;)

chx’s picture

I did? How so?

acrazyanimal’s picture

The patch I gave you was git commit aware and had my author info included in it. You committed the changes along with your 'Separate API and UI modules' changes and no cred was attributed to me whatsoever for actually doing the work to fix the 'Loads related entities' and adding the new 'Fetch relation endpoints' action. Stings a little to put effort into something, but not get the credit due. I'm sure you understand.

Commit c04134c on 7.x-1.x
by chx
Separate API and UI modules.

You did add my name to the commit after it for fixing the [], but still no authorship.

Adding a commit author

chx’s picture

I will take more care of this. Believe me, I understand more than you'd think how much this matters.

chx’s picture

I have re-committed this so that you got your credit. Thanks for your work.

acrazyanimal’s picture

Thanks chx, I appreciate the effort. :) I also appreciate this amazing module! Good work guys.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nicodv’s picture

Status: Closed (fixed) » Active

First, thanks to everyone involved in the creation and following development of this module, I've been having fun using it, although I recently ran into a problem related to what's been talked here:

I created a rule that relates a user with an OG group (relation type: "is tutor of"). Now I want to provide another rule for when that person stops being a tutor for that group, so I go to rules and try to use "loads related entities" but there is no way to find the exact relation of the current user and his/her group.

In few words: how do you delete a relation from rules?

thanks again, hope I explained myself and that someone can help here.

nico

chx’s picture

Status: Active » Closed (fixed)

Please file a separate support issue.

nicodv’s picture

i will

thanks